package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    //注入mapper
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        //调用mapper层查询数据库
        return deptMapper.findAll();
    }

    @Override
    public void deleteById(Integer id) {
        //调用mapper层删除部门数据
        deptMapper.deleteById(id);
    }

    @Override
    public void save(Dept dept) {
        //1. 填充创建时间、修改时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //2. 调用mapper层保存部门数据
        deptMapper.insert(dept);
    }
}
